import React from 'react';
import { Row, Input,Button } from 'antd';
import './login.css'
import Ontrial from './Ontrial'
import {smsList,SMSlogin,WXloginUrl} from '../../redux/login/login'
import { connect } from 'react-redux'
import {withRouter } from 'react-router-dom'
const Search = Input.Search;
@withRouter
@connect(
    state => state,
    { smsList,SMSlogin,WXloginUrl}
)
export default class SMSLogin extends React.Component{
    constructor(){
        super();
        this.state = {
            visible : false,
            code:60,
            codestate:false,
            wxBind:false
        }
    }
    componentWillReceiveProps(nextProps){
        if(!this.props.userLogin.code){
            // this.props.history.push('/menuList')
        }else{
          
        }
    }
    componentDidMount(){
        if(this.props.userLogin.binddata === 'true'){
            this.props.history.push('/menuList/1')
        }else if(!this.props.userLogin.binddata){
            this.props.history.push('/login/1')
        }
    }
  
    onSMSLogin(){
        let SMSIPhone = document.getElementById('SMSIPhone').value
        let smsCode = document.getElementById('smsCode').value
        if(this.props.userLogin.code === undefined || this.props.userLogin.code === '' || !this.props.userLogin.code){
            this.props.SMSlogin(SMSIPhone,smsCode)
        }else{
            this.props.WXloginUrl('','',SMSIPhone,smsCode)
        }
         
    }
    fPassword(){
        this.props.history.push('/login/2')
    }
   
    forgetpw(){
        let SMSIPhone = document.getElementById('SMSIPhone').value
        this.props.smsList(SMSIPhone);
        if(this.state.code === 60){
            console.log('获取验证码')
        let identTime = setInterval(()=>{
            if(this.state.code > 1){
                this.setState({
                    code:this.state.code - 1,
                    codestate:true
                })
            }else{
                console.log(this.state.code)
                this.setState({
                    code:60,
                    codestate:false
                })
                clearInterval(identTime);
            }
           
        },1000)
      }
    }
    render() {
        return (
            <div className='passWordList'>
                 <div >
                    <Input id='SMSIPhone' className='iPhone' style={{height:'40px'}} placeholder="手机号" />
                      <Search
                        id='smsCode'
                        style={{paddingTop:'20px'}}
                        placeholder="验证码"
                        enterButton= {this.state.codestate ? this.state.code+'秒' :'获取验证码'}
                        size="large"
                        onSearch={this.forgetpw.bind(this)}
                    />
                    <Button className='btnPrimary' onClick={this.onSMSLogin.bind(this)} style={{height:'40px'}} type="primary" block>立即登录</Button>
                    {/* <Button className='btnblock' style={{height:'40px'}}  block>微信登陆</Button> */}
                    <div className='forgetList'>
                    </div>
                 </div>
            </div>
        )
    }
}